/**
 * 简单模拟 request
 * @param time 时延
 * @param result 返回数据
 * @returns
 */
function sleep<T = undefined>(
  time: number,
  result?: T
): Promise<undefined extends T ? void : T> {
  return new Promise<undefined extends T ? void : T>(function (resolve) {
    setTimeout(() => {
      resolve(result as undefined extends T ? void : T);
    }, time);
  });
}

export default sleep;
